<template>
  <view class="page-order-index">
    <van-empty description="暂无数据" v-if="list_data.list.length == 0" />
    <view class="order-list" v-else>
      <view class="fly-panel" v-for="(item,index) in list_data.list" :key="index">
        <view class="hd">
          <text class="title">{{getName(item, 'consultType')}}</text>
          <text class="value" v-if="item.payState == 0">待支付</text>
          <text :class="'value order-status-'+ item.orderStatus" v-else>{{getName(item, 'orderStatus')}}</text>
        </view>
        <view class="bd">
          <view class="bd-ul">
            <fly-info label="就诊人：" :value="item.custName + ' ' + item.sex  + ' ' + item.age +'岁'" />
            <fly-info label="预约时间：" :value="item.makeStartDate.substring(0,10)+ ' ~ ' + item.makeEndDate.substring(0,10)" />
          </view>
        </view>
        <view class="ft">
          <view class="flex-block">
            <view>实付款 <text>￥{{item.payAmt}}</text></view>
							<van-button round type="info" plain size="small" @tap.stop.prevent="payOrder(item.lvtoConsultBillId)" v-if="item.payState== 0">去支付</van-button>
          </view>
        </view>
      </view>
      <view class="fly-panel">
        <view class="hd">
          <text class="title">粤G00001</text>
          <text :class="'value order-status-'+ item.orderStatus">{{getName(item, 'orderStatus')}}</text>
        </view>
        <view class="bd">
          <view class="bd-ul">
            <fly-info label="车辆类型：" value="xxx" />
            <fly-info label="行驶证到期日：" value="xxx" />
            <fly-info label="车牌颜色：" value="xxx" />
            <fly-info label="核定载质量：" value="xxx" />
          </view>
        </view>
        <view class="ft">
          <view class="align-left">载具所有人：xxxxx</view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>  
  import flyInfo from '@/components/flyInfo';
  import longList from '@/static/mixins/longList';
  export default {
    mixins:[longList],
    data(){
      return{
        api: '/lvto/lvtoConsultBill/xcx/page',
        initData:{
          orderStatus: [],
          consultType:[],
        },
      }
    },
    components:{
      flyInfo
    },
    onShow(){
      // this.getInitData();
      this.list_data.list = [{id:1}]
    },
    methods:{
      async getInitData(){
        let orderStatus = await this.$http('get', '/nursing/oms/aid/itemtrees/lvto_consult_order_status', {});
        this.initData.orderStatus = this.$utils.transformArray(orderStatus, 'itemId', 'itemName');
        let consultType = await this.$http('get', '/nursing/oms/aid/itemtrees/lvto_consult_type', {});
        this.initData.consultType = this.$utils.transformArray(consultType, 'itemId', 'itemName');
        this.getList('refresh');
      },
      getName(opt,type){
        let obj = this.initData[type].find(item => item.id == Number(opt[type]));
        return obj.name;
      },
      payOrder(billId){
        uni.login({
						success: res => {
							let params = {
                billId: billId,
                body: '咨询服务单支付',
                code: res.code,
                billType:0
              };
              this.$http('post', '/lvto/pay/payment',params, (data,msg) => {
                let obj = JSON.parse(data)
                uni.requestPayment({
                  provider: 'wxpay',
                  ...obj,
                  success: response => {
                    this.getList('refresh');
                  }
                })
              })
              
						},
					})
      },
    }
  }
</script>